package com.hqd.base.server.controller;

import com.hqd.base.client.model.entity.BaseGroup;
import com.hqd.base.server.service.BaseGroupService;
import com.hqd.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "系统组管理")
@RestController
public class BaseGroupController {
    @Autowired
    private BaseGroupService baseGroupService;

    @ApiOperation(value = "添加系统组")
    @PostMapping("/group/insertSelective")
    public ResultBody insertSelective(@RequestBody BaseGroup entity){
        baseGroupService.insertSelective(entity);
        return ResultBody.ok();
    }
    @ApiOperation(value = "修改系统组")
    @PostMapping("/group/updateByGroup")
    public ResultBody updateByGroup(@RequestBody BaseGroup entity){
        baseGroupService.updateBy(entity);
        return ResultBody.ok();
    }
    @ApiOperation(value = "添加员工或者领导")
    @PostMapping("/group/modifyGroupUsers")
    public ResultBody modifyGroupUsers(@RequestParam int groupId, String members, String leaders){
        baseGroupService.modifyGroupUsers(groupId,members,leaders);
        return ResultBody.ok();
    }
    @ApiOperation(value = "查询部门下所有员工")
    @PostMapping("/group/getAllUsersLeaders")
    public List<Long> getAllUsersWithDepartAndSubDepart(@RequestParam int groupId){
        List<Long> allUsersWithDepartAndSubDepart = baseGroupService.getAllUsersWithDepartAndSubDepart(groupId);
        return allUsersWithDepartAndSubDepart;
    }
}
